package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.VersionHistory;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author jh
 * 2018/9/18
 */
@Repository
public class VersionHistoryDao {

    @Resource
    private SqlSession sqlSession;

//    public VersionHistory getVersionHistoryByWhere(String versionNum,Long configAppId) {
//        Map<String, Object> map = new HashMap<>(4);
//        map.put("configAppId", configAppId);
//        map.put("versionNum", versionNum);
//        return sqlSession.selectOne("getVersionHistoryByWhere", map);
//    }
//
//    public VersionHistory getVersionHistory(String versionNum, Integer type, String appPackageId) {
//        Map<String, Object> map = new HashMap<>(4);
//        map.put("type", type);
//        map.put("appPackageId", appPackageId);
//        map.put("versionNum", versionNum);
//        return sqlSession.selectOne("getVersionHistory", map);
//    }

    public VersionHistory getLastForceUpdatingVersion(Integer type, String appPackageId) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("phoneSystem", type);
        map.put("appPackageId", appPackageId);
        return sqlSession.selectOne("getLastForceUpdatingVersion", map);
    }

    public VersionHistory getNewestVersion(Integer type, String appPackageId) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("phoneSystem", type);
        map.put("appPackageId", appPackageId);
        return sqlSession.selectOne("getNewestVersion", map);
    }

    public Boolean getVersionHistoryIsAudit(String versionNum, Integer type, String appPackageId, String channel) {
        Map<String, Object> map = new HashMap<>(8);
        map.put("phoneSystem", type);
        map.put("appPackageId", appPackageId);
        map.put("versionNum", versionNum);
        map.put("channel", channel);
        return sqlSession.selectOne("getVersionHistoryIsAudit", map);
    }
}
